#ifndef __LQ_ADC_H__
#define __LQ_ADC_H__

#include "lq_include.h"

/*
 * adc 通道 枚举   ADC0对应管脚 AN0
 */
typedef enum
{
    // ADC0可选引脚
    ADC0_CH0_A0 = 0x0000, // 0x0000
    ADC0_CH1_A1 = 0x0001,
    ADC0_CH2_A2 = 0x0002,
    ADC0_CH3_A3 = 0x0003,
    ADC0_CH4_A4 = 0x0004,
    ADC0_CH5_A5 = 0x0005,
    ADC0_CH6_A6 = 0x0006,
    ADC0_CH7_A7 = 0x0007,

    // ADC1可选引脚
    ADC1_CH0_A8 = 0x0100,
    ADC1_CH2_A10 = 0x0102,
    ADC1_CH3_A11 = 0x0103,
    ADC1_CH4_A12 = 0x0104,
    ADC1_CH5_A13 = 0x0105,

    // ADC2可选引脚
    ADC2_CH0_A16 = 0x0200, // 0x0200
    ADC2_CH1_A17 = 0x0201, // 0x0201
    ADC2_CH4_A20 = 0x0204, // 0x0204
    ADC2_CH5_A21 = 0x0205, // 0x0205

    // ADC3可选引脚
    ADC3_CH0_A24 = 0x0300, // 0x0300
    ADC3_CH1_A25 = 0x0301, // 0x0301

    // ADC8可选引脚
    ADC8_CH3_A35 = 0x0803, //
    ADC8_CH4_A36 = 0x0804,
    ADC8_CH5_A37 = 0x0805,
    ADC8_CH6_A38 = 0x0806,
    ADC8_CH7_A39 = 0x0807,
    ADC8_CH10_A42 = 0x080A,
    ADC8_CH11_A43 = 0x080B,
    ADC8_CH12_A44 = 0x080C,
    ADC8_CH13_A45 = 0x080D,
    ADC8_CH14_A46 = 0x080E,
    ADC8_CH15_A47 = 0x080F,
    // ADC0可选引脚
    // ADC0_CH0_A0 = 0 * 16 + 0,
    // ADC0_CH1_A1,
    // ADC0_CH2_A2,
    // ADC0_CH3_A3,
    // ADC0_CH4_A4,
    // ADC0_CH5_A5,
    // ADC0_CH6_A6,
    // ADC0_CH7_A7,

    // // ADC1可选引脚
    // ADC1_CH0_A8 = 1 * 16 + 0,
    // ADC1_CH2_A10 = 1 * 16 + 2,
    // ADC1_CH3_A11,
    // ADC1_CH4_A12,
    // ADC1_CH5_A13,

    // // ADC2可选引脚
    // ADC2_CH0_A16 = 2 * 16 + 0,
    // ADC2_CH1_A17 = 2 * 16 + 1,
    // ADC2_CH4_A20 = 2 * 16 + 4,
    // ADC2_CH5_A21 = 2 * 16 + 5,

    // // ADC3可选引脚
    // ADC3_CH0_A24 = 3 * 16 + 0,
    // ADC3_CH1_A25 = 3 * 16 + 1,

    // // ADC8可选引脚
    // ADC8_CH3_A35 = 8 * 16 + 3,
    // ADC8_CH4_A36,
    // ADC8_CH5_A37,
    // ADC8_CH6_A38,
    // ADC8_CH7_A39,
    // ADC8_CH10_A42 = 8 * 16 + 10,
    // ADC8_CH11_A43,
    // ADC8_CH12_A44,
    // ADC8_CH13_A45,
    // ADC8_CH14_A46,
    // ADC8_CH15_A47,
} ADC_Channel_t;

// 此枚举定义不允许用户修改

/* 获取ADC对应组 */
#define ADC_GetGroup(ADC_Channel) ((ADC_Channel & 0xff00) >> 8)
/* 获取ADC对应通道 */
#define ADC_GetChannel(ADC_Channel) (ADC_Channel & 0x00ff)

// /* 获取ADC对应组 */
// #define ADC_GetGroup(ADC_Channel) (ADC_Channel / 16)
// /* 获取ADC对应通道 */
// #define ADC_GetChannel(ADC_Channel) (ADC_Channel % 16)

void ADC_InitConfig(ADC_Channel_t channel, unsigned long Freq_Hz);
unsigned short ADC_Read(ADC_Channel_t chn);
unsigned short ADC_ReadAverage(ADC_Channel_t chn, unsigned char count);

#endif /* __LQ_ADC_H__ */
